<?php

class Admin_SpecialtextController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
       $this->_helper->layout()->disableLayout();
       Zend_Loader::loadFile('../application/admin/models/Specialtext.php');
       $Specialtext_model = new Specialtext();
       $Specialtext_arr = $Specialtext_model->listSpecialtexts();
       $this->view->Specialtext_arr = $Specialtext_arr;
     
    }
    
    public function addAction()
    {
        $this->_helper->layout()->disableLayout();
		Zend_Loader::loadFile('../application/admin/models/Specialtext.php');
        $mod_Specialtext = new Specialtext();
        $tpl_arr=$mod_Specialtext->getparentids();
        $this->view->title = "Add Specialtext";
        $this->view->tpl_arr = $tpl_arr;      
    }
    
    public function doaddAction()
	{
		Zend_Loader::loadFile('../application/admin/models/Specialtext.php');
		$Specialtext_model = new Specialtext();
		$request = $this->getRequest();
		
		if ($this->getRequest()->isPost()) {            
			$Specialtext_model = new Specialtext();
			$form_values = $request->getPost();
                        //print_r($form_values);
			$add_Specialtext = $Specialtext_model->addSpecialtext($form_values);
		}
		
		exit;
	}

    public function editAction()
    {
    	$this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Specialtext.php'); 
        $Specialtext_model = new Specialtext();
        $controller = $this->getRequest()->getControllerName();
		$action = $this->getRequest()->getActionName();
		$Specialtext_id = $this->_getParam('id', 0);
		$options = array("action"=>$action, "Specialtext_id"=>$Specialtext_id);
                 $tpl_arr=$Specialtext_model->getparentids();
        $this->view->Specialtext_id = $Specialtext_id;
        $Specialtext_arr = $Specialtext_model->getSpecialtext($Specialtext_id);
      //  print_r($Specialtext_arr);exit;
        $this->view->tpl_arr = $tpl_arr;     
        $this->view->specialtext_arr = $Specialtext_arr;
    }

    public function  doeditAction()
    {
        
        $this->_helper->layout()->disableLayout();
   		Zend_Loader::loadFile('../application/admin/models/Specialtext.php');
        $Specialtext_model = new Specialtext();
    //    echo "1233";exit;
        $request = $this->getRequest();
		if ($this->getRequest()->isPost()) {
                     
			$Specialtext_model = new Specialtext();
                       
			$form_values = $request->getPost();

			$update_Specialtext = $Specialtext_model->updateSpecialtext($form_values);
		}
		
		exit;
    }
    
    public function deleteAction()
    {
        $this->_helper->layout()->disableLayout();
        $Specialtext_id = $this->_getParam('id', 0);
        Zend_Loader::loadFile('../application/admin/models/Specialtext.php');
        $Specialtext_model = new Specialtext();
        $Specialtext_model->deleteSpecialtext($Specialtext_id);
        //$this->_helper->redirector('index');
        exit;
    }
    
    public function listsubuserAction()
    {
    	$this->_helper->layout()->disableLayout();
    	Zend_Loader::loadFile('../application/admin/models/Specialtext.php');
    	
    	$mod_Specialtext = new Specialtext();
    	$mail = new Zend_Mail();
    	$request = $this->getRequest();
    	$Specialtext_id = $request->getParam('Specialtext_id');
    	$subs_user_arr_en = $mod_Specialtext->getSubscribeUsersByLang('en');
    	$subs_user_arr_ru = $mod_Specialtext->getSubscribeUsersByLang('ru');
    	$Specialtext_arr = $mod_Specialtext->getSpecialtext($Specialtext_id);
    	
    	$this->view->Specialtext_id = $Specialtext_id;
    	//$this->view->Specialtext_content_en = $Specialtext_arr['Specialtext_content_en'];
    	//$this->view->Specialtext_content_ru = $Specialtext_arr['Specialtext_content_ru'];
    	
    	$this->view->subs_user_arr_en = $subs_user_arr_en;
    	$this->view->subs_user_arr_ru = $subs_user_arr_ru;
    	
    }
    
    public function sendSpecialtextAction()
    {
    	$this->_helper->layout()->disableLayout();
    	Zend_Loader::loadFile('../application/admin/models/Specialtext.php');
    	$mod_Specialtext = new Specialtext();
    	
    	$request = $this->getRequest();
    	$Specialtext_id = $request->getParam('Specialtext_id');
    	$lang = $request->getParam('lang');
    	$email = $request->getParam('email');
    	
    	$mail = new Zend_Mail();
    	//$mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64);
    	//$mail->CharSet = 'UTF-8';
    	$Specialtext_arr = $mod_Specialtext->getSpecialtext($Specialtext_id);
    	
    	if($lang == 'en') {
    		$Specialtext_content_en = $Specialtext_arr['Specialtext_content_en'];
    		$msg = $Specialtext_content_en;
    		$subject = "Warnertravellers Specialtext";
    	} else if($lang == 'ru') {
    		$Specialtext_content_ru = $Specialtext_arr['Specialtext_content_ru'];
    		$msg = $Specialtext_content_ru;
    		$subject = "Warner ??? ????";
    	}
    	
    	
	    //$headers = "Content-type: text/html; charset=UTF-8\r\n";
		$headers = "From: Warnertravellers.com <info@warnertravellers.com>\r\n";
		
		$mail->setBodyHtml($msg);
	    $mail ->setFrom($headers);
	    $mail->setSubject($subject);
	    
		// for the testing purpose we are sending email to the localhost.
	    $mail->addTo('info@localhost'); 
	    
	    
	    if($mail->send()) {
	    	echo "Specialtext has been successfully send";
	    }
    	
    	exit;
    }
}